<?php

namespace app\common\logic;

/**
 * 留言管理逻辑
 */
class Serve extends LogicBase
{

    /**
     * 获取留言管理列表
     */
    public function getServeList($where = [], $field = '*', $order = '')
    {
        
        $where[ DATA_STATUS_NAME] = ['neq', DATA_DELETE];
        
        return $this->modelServe->getList($where, $field, $order, DB_LIST_ROWS);
    }
    
    
    /**
     * 获取留言管理列表搜索条件
     */
    public function getWhere($data = [])
    {
        
        $where = [];
        
        !empty($data['search_data']) && $where['a.ask_name|a.question'] = ['like', '%'.$data['search_data'].'%'];
        
        return $where;
    }
    
     /**
     * 留言管理信息编辑
     */
    public function messageEdit($data = [],$url)
    {

        $validate_result = $this->validateServe->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateServe->getError()];
        }
        
        $url = url($url);   
        
        $data['ask_time'] = time();
       
        $result = $this->modelServe->setInfo($data);
        
        return $result ? [RESULT_SUCCESS, '留言管理操作成功', $url] : [RESULT_ERROR, $this->modelServe->getError()];
    }
}

